package PostBar.Http;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class GetVcodeImage {
	private String urlImage;
	private String cookie;
	public GetVcodeImage(String urlImage,String cookie) {
		this.urlImage=urlImage;
		this.cookie=cookie;
	}
	public void download()
	{
		try {
			URL url = new URL(urlImage);
			URLConnection con =url.openConnection();
			con.setRequestProperty("Cookie", cookie);
			con.setConnectTimeout(5*1000);
			InputStream isInputStream = con.getInputStream();
			byte[] bs = new byte[1024];
			int length=0;
			File file = new File("Vcode.jpg");
			if (file.exists()) {
				file.mkdir();
			}
			OutputStream os = new FileOutputStream(file);
			while((length=isInputStream.read(bs))!=-1)
			{
				os.write(bs,0,length);
			}
			os.close();
			isInputStream.close();
			
		} catch (MalformedURLException e) {
			
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
